package org.example.shoppingsystem.controller;

import org.example.shoppingsystem.model.Product;
import org.example.shoppingsystem.service.ProductServer;
import org.example.shoppingsystem.service.ProductServerImpl;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.sql.SQLException;
import java.util.List;

@Controller
public class ProductController {
    private ProductServer productServer = new ProductServerImpl();

    @GetMapping("/products")
    public String showProducts(Model model) {
        try {
            List<Product> products = productServer.findAllProducts();
            model.addAttribute("products", products);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return "products";
    }
}